//
//  STTAViewController.m
//  CollTest
//
//  Created by codew on 11/20/21.
//

#import "STTAViewController.h"

@interface STTAViewController ()

@property (nonatomic, strong) UIColor * orStatusBarColor;
@end

@implementation STTAViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    

}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self updateStatusBarColorWillAppear];
}

- (void)updateStatusBarColorWillAppear
{
    if (@available(iOS 13.0, *)) {
        UIView *statusBar = [[UIView alloc]initWithFrame:[UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame];
        if (!self.orStatusBarColor) {
            self.orStatusBarColor = statusBar.backgroundColor;
        }
        
        statusBar.backgroundColor = [UIColor colorWithHexString:@"#4974F5"];;
        [[UIApplication sharedApplication].keyWindow addSubview:statusBar];
    } else {
        // Fallback on earlier versions
        UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
        if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
            
            if (!self.orStatusBarColor) {
                self.orStatusBarColor = statusBar.backgroundColor;
            }
            statusBar.backgroundColor = [UIColor colorWithHexString:@"#4974F5"];;
        }
    }
    
}

- (void)updateStatusBarColorWillDisappear
{
    if (@available(iOS 13.0, *)) {
        UIView *statusBar = [[UIView alloc]initWithFrame:[UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame];
//        if (!self.orStatusBarColor) {
//            self.orStatusBarColor = statusBar.backgroundColor;
//        }
        
        statusBar.backgroundColor = self.orStatusBarColor;//[UIColor colorWithHexString:@"#4974F5"];;
        [[UIApplication sharedApplication].keyWindow addSubview:statusBar];
    } else {
        // Fallback on earlier versions
        UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
        if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
            
//            if (!self.orStatusBarColor) {
//                self.orStatusBarColor = statusBar.backgroundColor;
//            }
            statusBar.backgroundColor = self.orStatusBarColor;//[UIColor colorWithHexString:@"#4974F5"];;
        }
    }

}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [self updateStatusBarColorWillDisappear];
}
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    
    
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
